import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import './assets/css/main.css'
import { createPinia } from 'pinia' // 导入 Pinia
const app = createApp(App)
const pinia = createPinia() // 创建 Pinia 实例
import { useAuthStore } from '@/stores/auth'
app.use(pinia) // 安装 Pinia
app.use(router)
app.use(ElementPlus)

app.mount('#app')

import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';

pinia.use(piniaPluginPersistedstate);


router.beforeEach(async (to, from, next) => {
  const authStore = useAuthStore();
  await authStore.checkAuth();
  next();
});
// 在main.js中添加
router.beforeResolve((to, from, next) => {
    if (to.matched.some(record => record.meta.preload)) {
      // 预加载目标路由组件
      to.matched.forEach(record => {
        if (typeof record.components.default === 'function') {
          record.components.default()
        }
      })
    }
    next()
  })
